package net.xiduth.game.player.content;

import java.util.Random;

import net.xiduth.game.World;
import net.xiduth.game.player.Player;

/**
 * @Author: Apache Ah64, Thanks Apache :)
 */
public class TriviaBot {
	
	private static String questions [][] = {
		{"Figure out this anagram: 'duithx'", "xiduth"},
		{"What NPC do you speak with when you first make a character?", "cook"},
		{"Through what Minigame do you obtain Void?", "dark invasion"},
		{"How does one obtain Goliath gloves?", "dominion tower"},
		{"What weapon is Delrith's weakness?", "silverlight"},
		{"How many altars are there at home?", "3"},
		{"What is temple under the ::boss area called?", "ancient temple"},
		{"How much does regular donator status cost?", "$15"},
		{"How many times does Sagittare hit per attack in the rift?", "3"},
		{"What level is Saggittare from the Elemental Rift area?", "1337"},
		{"What was the first obsidian weapon Jagex released?", "Dark dagger"},
		{"Who are the developers of Xiduth?", "oracle and google"},
		{"What cache revision is Xiduth?", "718"},
		{"Who is founder of Xiduth?", "jaejoong"},
		{"Figoure out this anagram: 'ykle'", "kyle"},
		{"What is the maximum total level you can achieve?", "3000"},
		{"What gaming genre is Xiduth?", "MMORPG"},
		{"In what year was RuneScape established?", "2001"},
		{"What is the max skill cap?", "99"},
		{"How many portals are there at clan wars?", "3"},
		{"What is maximum combat level in Xiduth?", "138"},
		{"Is a tomato a fruit or a vegetable?", "Fruit"},
		{"How many legs does a spider have?", "8"},
		{"How much does a rune scimitar sell for in the general store?", "12800"},
		{"Figure out this anagram: 'Geer Tips'", "prestige"},
		{"Figure out this anagram: 'gjaojoen'", "jaejoong"},
		{"Figure out this anagram: 'tcas'", "cats"},
		{"Figure out this anagram: 'obom'", "boom"},
		{"What is 'K-pop'?", "korean pop"},
		{"What command do you use to teleport around Xiduth?", "::crystal"},
		{"How many barrows brothers were there originally?", "5"},
		{"What is north of ::home?", "nothing"},
		{"How many cooking ranges are there at ::home?", "0"},
		{"How many ranks are there in the rank system?", "8"},
		{"In what year was the Duplication Glitch in RuneScape?", "2003"},
		{"How many squeal of fortune spins can you vote for?", "2"},
		{"How many PvM points are required to buy thok's sword?", "30000"},
		{"What is the name of the new sword?", "thok's sword"},
		{"What is the first ancient spell?", "smoke rush"},
		{"What is the most powerful curse?", "Turmoil"},
		{"How much of a percentage does a dragon dagger special require?", "25%"},
		{"How much of a percentage does a thok's sword special require?", "25%"},
		{"What color is the donator sign?", "Green"},
		{"What's the hardest level to get max level in?", "dungeoneering"},
		{"What is the best free to play armour?", "Rune armor"},
		{"Figure out this anagram: 'oset irot'", "tortoise"},
		{"Who is the dungeoneering NPC?", "thok"},
		{"How much xp is required to achieve 120 dungeoneering?", "104m"},
		{"What do you receive when a fire disappears?", "Ashes"},
		{"What is the name of the new firecape?", "TokHaar-Kal"},
		{"What is the maximum amount of xp you can gain per skill?", "200m"},
		{"Who sells Loyalty items?", "xuan"}
	};
	
	public static int questionid = -1;
	public static int round = 0;
	public static boolean victory = false;

	public static void Run() {
		int rand = RandomQuestion();
		questionid = rand;
		victory = false;
		for(Player participant : World.getPlayers()) {
			if(participant == null)
				continue;
				participant.getPackets().sendGameMessage("<col=56A5EC>[Trivia] "+questions[rand][0]+"</col>");
		}
	}
	
	public static void sendRoundWinner(String winner, Player player) {
		for(Player participant : World.getPlayers()) {
			if(participant == null)
				continue;
				victory = true;
				player.TriviaPoints+= 1;
				player.getPackets().sendGameMessage("<col=56A5EC>[Trivia] "+winner+", you now have "+player.TriviaPoints+" Trivia Points.</col>");
				participant.getPackets().sendGameMessage("<col=56A5EC>[Winner] <col=FF0000>"+ winner +"</col><col=56A5EC> answered the question correctly!</col>");
		}
	}
	
	public static void verifyAnswer(final Player player, String answer) {
		if(victory) {
			player.getPackets().sendGameMessage("That round has already been won, wait for the next round.");
		} else if(questions[questionid][1].equalsIgnoreCase(answer)) {
			round++;
			sendRoundWinner(player.getDisplayName(), player);
		} else {
			player.getPackets().sendGameMessage("That answer wasn't correct, please try it again.");
		}
	}
	
	public static int RandomQuestion() {
		int random = 0;
		Random rand = new Random();
		random = rand.nextInt(questions.length);
		return random;
	}
	
	public static boolean TriviaArea(final Player participant) {
		if(participant.getX() >= 2630 && participant.getX() <= 2660 && participant.getY() >= 9377 && participant.getY() <= 9400) {
			return true;
		}
		return false;
	}
}
